package com.tianya.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tianya.domain.dto.HomeVisitRequestDTO;
import com.tianya.domain.entity.Homevisit;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.HomevisitService;
import com.tianya.mapper.HomevisitMapper;
import org.springframework.stereotype.Service;

/**
* @author 86191
* @description 针对表【homevisit(家访记录表)】的数据库操作Service实现
* @createDate 2025-05-24 18:59:41
*/
@Service
public class HomevisitServiceImpl extends ServiceImpl<HomevisitMapper, Homevisit>
    implements HomevisitService{
    @Override
    public void createHomeVisit(HomeVisitRequestDTO homeVisitRequestDTO) {
        Homevisit homevisit = Homevisit.builder()
                .teacherId(homeVisitRequestDTO.getTeacherId())
                .studentId(homeVisitRequestDTO.getStudentId())
                .visitDate(homeVisitRequestDTO.getVisitDate())
                .location(homeVisitRequestDTO.getLocation())
                .notes(homeVisitRequestDTO.getNotes())
                .build();
        save(homevisit);
    }

    @Override
    public PageResultVO<Homevisit> pageHomeVisit(Integer pageNum, Integer pageSize, HomeVisitRequestDTO homeVisitRequestDTO) {
        Page<Homevisit> page = Page.of(pageNum, pageSize);
        QueryWrapper<Homevisit> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(Homevisit::getTeacherId, homeVisitRequestDTO.getTeacherId())
                .eq(Homevisit::getStudentId, homeVisitRequestDTO.getStudentId())
                .eq(Homevisit::getVisitDate, homeVisitRequestDTO.getVisitDate())
                .eq(Homevisit::getLocation, homeVisitRequestDTO.getLocation());
        Page<Homevisit> homevisitPage = page(page, queryWrapper);

        return PageResultVO.<Homevisit>builder()
                .total(homevisitPage.getTotal())
                .records(homevisitPage.getRecords())
                .build();
    }
}




